package com.ja.openchat.ui.chat.ext;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.ja.openchat.R;
import com.zy.openchat.core.model.message.ChatInfo;
import com.zy.openchat.core.model.user.UserInfo;
import com.ja.openchat.ui.chat.MobileContactHomeActivity;
import com.ja.openchat.ui.chat.annotation.ExtContextMenuItem;
import com.ja.openchat.ui.chat.ext.core.ConversationExt;
import com.ja.openchat.ui.chat.listener.OnContactSendListener;
import com.ja.openchat.views.PostContactDialog;


public class ContactExt extends ConversationExt {



    /**
     * @param containerView 扩展view的container
     * @param conversation
     */
    @ExtContextMenuItem
    public void pickContact(View containerView, ChatInfo conversation) {
        startActivityForResult(MobileContactHomeActivity.getActivityForResult(fragment.getContext()),111);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK&&data != null&&data.getParcelableExtra("user")!=null) {
            UserInfo userInfo = (UserInfo)data.getParcelableExtra("user");
            if(userInfo!=null){
                PostContactDialog.show(fragment.getContext(), userInfo, new OnContactSendListener() {
                    @Override
                    public void toSend(String content) {
                        messageViewModel.sendContactMsg(conversation,userInfo);
                        if(!TextUtils.isEmpty(content)){
                            messageViewModel.sendTextMsg(conversation,content);
                        }
                    }
                });

            }
        }
    }

    @Override
    public boolean filter(ChatInfo conversation) {
        return conversation.isMyFovChat()||conversation.isGroupSendChat();
    }

    @Override
    public int priority() {
        return 6;
    }

    @Override
    public int iconResId() {
        return R.drawable.icon_card;
//        return R.mipmap.menu_contact;
    }

    @Override
    public String title(Context context) {
        return context.getString(R.string.business_card_text);
    }

    @Override
    public String contextMenuTitle(Context context, String tag) {
        return title(context);
    }
}
